<?php
namespace Erp\Controller;
use Think\Controller;
use Erp\C\Orders;
use Erp\C\Xpublic;
use Erp\Model;
use Fn;
use Erp\C\Orders\Tn;
class OrdersController  extends Controller {
	public function __call($a,$b){
		$this->_noAuthGetTnPdf();
	}
    /**
     * @param orders 订单号
     */
	public function _noAuthGetTnPdf() {
		$orders = I('get.orders', '', 'trim'); //得到订单号，可能为1条，也可能为多条
		$orders = explode(',', $orders);
		$shipping = new Tn\ShippingTn();
	    $shipping->getTnByOrders($orders); //取Tn
		$shipping->getLableByOrders($orders);//取面单
		$shipping->putOrdersById($orders);
	}
	/**
	 * 合并order信息
	 * @param init $o_id
	 */
	public function combinOrderInfo($ordersId) {
        $table = '';
        $map = '';
        $data = $ordersId;
        $method = 'combinOrderInfo';
        $res = A('OrdersInfo')->Order($table,$map,$method,$data);
        $res = json_decode($res,true);
        return $res;
	}
    /**
     * @param $ordersId
     * @return mixed
     * 订单信息
     */
	public function getOrders($orders){
        $table = 'orders';
        $where = array('orders_id'=>array('IN',$orders));   //订单号传值
        $method = 'select';
        $data = '';
        $res = A('OrdersInfo')->Order($table,$where,$method,$data);
        $res = json_decode($res,true);
        return $res;
	}
    /**
     * @param $ordersId
     * @return mixed
     * 订单状态
     */
	public function getOrdersStatus($ordersId){
        $table = 'orders';
        $map = array('orders_id'=>$ordersId);   //订单号传值
        $method = 'find';
        $data = '';
        $res = A('OrdersInfo')->Order($table,$map,$method,$data);
        $res = json_decode($res,true);
        return $res['orders_status'];
	}
    /**
     * @return bool
     * 保存数据到订单表
     */
	public function saveData($ordersStatusChildren,$ordersId){
        $param = array();
        $param['table'] = 'orders';
        $param['where'] = ['orders_id'=>$ordersId];
        $param['method'] = 'save';
        $param['data'] = $ordersStatusChildren;
        $json = json_encode($param);
        $url = 'http://192.168.0.235/erp2/index.php?s=Erp-CrontabManage-operateMysql&param='.$json;
        $res = file_get_contents($url);
        return $res;
    }
    /**
     * @param $id
     * @param $msg
     * @return mixed
     * 日志记录
     */
    public function saveOrderHistory($id,$msg){
        $param = array();
        $param['table'] = 'orders_history';
        $param['method'] = 'add';
        $param['data'] = [
            'orders_id'=>$id,
            'orders_history_create_date' => date("Y-m-d H:i:s",time()),
            'orders_history_create_time' => time(),
            'user_id' => 868,
            'orders_history_remark' => $msg
        ];
        $json = json_encode($param);
        $json = urlencode($json);
        $url = 'http://192.168.0.235/erp2/index.php?s=Erp-CrontabManage-operateMysql&param='.$json;
        $res = file_get_contents($url);
        return $res ;
    }
}
